feat(command-center): autofill empty cells with recent active tasks#2212
feat(command-center): autofill empty cells with recent active tasks#2212richardsolomou wants to merge 2 commits into
Conversation
When the user opens the Command Center and no tasks are attached, populate empty cells with their tasks updated in the past 2 hours, ordered by most recent activity. Generated-By: PostHog Code Task-Id: 427c51ec-695b-4203-9ac2-bb79ea575422
Prompt To Fix All With AIFix the following 3 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 3
apps/code/src/renderer/features/command-center/hooks/useAutofillCommandCenter.ts:19-20
The hook guards on `workspacesFetched` but has no equivalent guard for the tasks query. `useTasks()` returns its data defaulted to `[]`, so if workspaces resolve first (common when they are cached from a previous mount), the effect fires immediately with an empty `tasks` array, finds zero candidates, sets `hasRunRef.current = true`, and exits. When the tasks response eventually arrives, the dependency change re-runs the effect — but `hasRunRef.current` is already `true`, so it bails. The autofill silently never runs.
```suggestion
const { data: tasks = [], isFetched: tasksFetched } = useTasks();
const { data: workspaces, isFetched: workspacesFetched } = useWorkspaces();
```
### Issue 2 of 3
apps/code/src/renderer/features/command-center/hooks/useAutofillCommandCenter.ts:30
The `workspacesFetched` guard needs a parallel `tasksFetched` guard so the effect waits for both data sources before proceeding.
```suggestion
if (!workspacesFetched || !workspaces) return;
if (!tasksFetched) return;
```
### Issue 3 of 3
apps/code/src/renderer/features/command-center/stores/commandCenterStore.test.ts:26-73
The five `autofillCells` tests share the same pattern — `setState`, call `autofillCells(input)`, assert `cells`. The team's preference is parameterised tests. The first, third, fourth, and fifth cases could be collapsed into a single `it.each` table covering `(input, expectedCells, expectedActiveTaskId)`, reducing duplication and making it easy to add edge cases in future.
Reviews (1): Last reviewed commit: "feat(command-center): autofill empty cel..." | Re-trigger Greptile |
| const { data: tasks = [] } = useTasks(); | ||
| const { data: workspaces, isFetched: workspacesFetched } = useWorkspaces(); |
There was a problem hiding this comment.
The hook guards on
workspacesFetched but has no equivalent guard for the tasks query. useTasks() returns its data defaulted to [], so if workspaces resolve first (common when they are cached from a previous mount), the effect fires immediately with an empty tasks array, finds zero candidates, sets hasRunRef.current = true, and exits. When the tasks response eventually arrives, the dependency change re-runs the effect — but hasRunRef.current is already true, so it bails. The autofill silently never runs.
| const { data: tasks = [] } = useTasks(); | |
| const { data: workspaces, isFetched: workspacesFetched } = useWorkspaces(); | |
| const { data: tasks = [], isFetched: tasksFetched } = useTasks(); | |
| const { data: workspaces, isFetched: workspacesFetched } = useWorkspaces(); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/code/src/renderer/features/command-center/hooks/useAutofillCommandCenter.ts
Line: 19-20
Comment:
The hook guards on `workspacesFetched` but has no equivalent guard for the tasks query. `useTasks()` returns its data defaulted to `[]`, so if workspaces resolve first (common when they are cached from a previous mount), the effect fires immediately with an empty `tasks` array, finds zero candidates, sets `hasRunRef.current = true`, and exits. When the tasks response eventually arrives, the dependency change re-runs the effect — but `hasRunRef.current` is already `true`, so it bails. The autofill silently never runs.
```suggestion
const { data: tasks = [], isFetched: tasksFetched } = useTasks();
const { data: workspaces, isFetched: workspacesFetched } = useWorkspaces();
```
How can I resolve this? If you propose a fix, please make it concise.|
|
||
| useEffect(() => { | ||
| if (hasRunRef.current) return; | ||
| if (!workspacesFetched || !workspaces) return; |
There was a problem hiding this comment.
The
workspacesFetched guard needs a parallel tasksFetched guard so the effect waits for both data sources before proceeding.
| if (!workspacesFetched || !workspaces) return; | |
| if (!workspacesFetched || !workspaces) return; | |
| if (!tasksFetched) return; |
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/code/src/renderer/features/command-center/hooks/useAutofillCommandCenter.ts
Line: 30
Comment:
The `workspacesFetched` guard needs a parallel `tasksFetched` guard so the effect waits for both data sources before proceeding.
```suggestion
if (!workspacesFetched || !workspaces) return;
if (!tasksFetched) return;
```
How can I resolve this? If you propose a fix, please make it concise.| it("fills empty cells from index 0", () => { | ||
| useCommandCenterStore.getState().autofillCells(["t1", "t2"]); | ||
| expect(useCommandCenterStore.getState().cells).toEqual([ | ||
| "t1", | ||
| "t2", | ||
| null, | ||
| null, | ||
| ]); | ||
| }); | ||
|
|
||
| it("does nothing when any cell is already populated", () => { | ||
| useCommandCenterStore.setState({ cells: [null, "existing", null, null] }); | ||
| useCommandCenterStore.getState().autofillCells(["t1", "t2"]); | ||
| expect(useCommandCenterStore.getState().cells).toEqual([ | ||
| null, | ||
| "existing", | ||
| null, | ||
| null, | ||
| ]); | ||
| }); | ||
|
|
||
| it("ignores empty task list", () => { | ||
| useCommandCenterStore.getState().autofillCells([]); | ||
| expect(useCommandCenterStore.getState().cells).toEqual([ | ||
| null, | ||
| null, | ||
| null, | ||
| null, | ||
| ]); | ||
| }); | ||
|
|
||
| it("caps fill at the number of cells", () => { | ||
| useCommandCenterStore | ||
| .getState() | ||
| .autofillCells(["t1", "t2", "t3", "t4", "t5", "t6"]); | ||
| expect(useCommandCenterStore.getState().cells).toEqual([ | ||
| "t1", | ||
| "t2", | ||
| "t3", | ||
| "t4", | ||
| ]); | ||
| }); | ||
|
|
||
| it("does not set activeTaskId", () => { | ||
| useCommandCenterStore.getState().autofillCells(["t1"]); | ||
| expect(useCommandCenterStore.getState().activeTaskId).toBeNull(); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
The five
autofillCells tests share the same pattern — setState, call autofillCells(input), assert cells. The team's preference is parameterised tests. The first, third, fourth, and fifth cases could be collapsed into a single it.each table covering (input, expectedCells, expectedActiveTaskId), reducing duplication and making it easy to add edge cases in future.
Context Used: Do not attempt to comment on incorrect alphabetica... (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/code/src/renderer/features/command-center/stores/commandCenterStore.test.ts
Line: 26-73
Comment:
The five `autofillCells` tests share the same pattern — `setState`, call `autofillCells(input)`, assert `cells`. The team's preference is parameterised tests. The first, third, fourth, and fifth cases could be collapsed into a single `it.each` table covering `(input, expectedCells, expectedActiveTaskId)`, reducing duplication and making it easy to add edge cases in future.
**Context Used:** Do not attempt to comment on incorrect alphabetica... ([source](https://app.greptile.com/review/custom-context?memory=instruction-0))
How can I resolve this? If you propose a fix, please make it concise.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
…ests Address Greptile review on PR #2212: - The hook only waited on workspaces. useTasks() defaults data to [], so if workspaces were cached and resolved first the effect ran with an empty tasks array, found zero candidates, set hasRunRef true and bailed — the later tasks response could never trigger the autofill. Add a tasksFetched guard so both sources must be loaded. - Collapse the autofillCells test trio into an it.each table per repo convention. Generated-By: PostHog Code Task-Id: 427c51ec-695b-4203-9ac2-bb79ea575422
Problem
When opening the Command Center with no tasks attached, users have to manually re-pick the same tasks they were just working on. This adds friction every time they return to the view.
Closes #1630
Changes
commandCenterStore.ts— newautofillCells(taskIds)action; no-op if any cell is already populated.useAutofillCommandCenter.ts— new hook that, on mount, finds tasks updated within the last 2 hours (max oftask.updated_atandlatest_run.updated_at), filters to non-archived tasks with a workspace, sorts by most recent activity, and assigns up to the grid size into the empty cells.CommandCenterView.tsx— calls the hook on mount. AuseRefguard runs the autofill at most once per mount, so manually clearing cells mid-session does not re-trigger it; navigating away and back does.commandCenterStore.test.ts— 5 unit tests covering the empty-cell guard, full-cell short-circuit, cell-count cap, empty-input no-op, and active-task-id non-effect.How did you test this?
pnpm --filter code typecheck— passes.pnpm --filter code test commandCenterStore— 5/5 tests pass.pnpm lint— clean (biome auto-formatted one file).Manual UI verification not run — flagging explicitly per the agent guidelines.
Publish to changelog?
no
Created with PostHog Code